package groupb6.shopsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import groupb6.shopsystem.pojo.entity.Destination;
import groupb6.shopsystem.pojo.form.UpdateAddressForm;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DestinationMapper extends BaseMapper<Destination> {
    @Select("select * from tb_destination where user_id = #{user_id}")
    List<Destination> getByUser_id(Integer user_id);

    @Update("update tb_destination set name = #{name}, phone = #{phone}, address = #{address} where id = #{id}")
    void updateDestById(UpdateAddressForm updateAddressForm);

    @Update("update tb_destination set is_default = 0 where user_id = #{user_id}")
    void changeDefaultOtherDestByUserId(Integer user_id);

    @Update("update tb_destination set is_default = 1 where id = #{id}")
    void changeDefaultDestById(Integer id);

    @Delete("delete from tb_destination where id = #{id}")
    void deleteDestById(Integer id);
}
